﻿
using MesAPI.Models.UserInfoMange;
using Microsoft.EntityFrameworkCore;
using PublicModelsAndEntities.Models.MainsortRecord;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WebApplication1.Entities;
using XinjeMesProgram.Entities.BookInfo;
using XinjeMesProgram.Entities.Maintenance;
using XinjeMesProgram.Entities.Material;
using XinjeMesProgram.Entities.RoleAndUser;
using XinjeMesProgram.Entities.User;

namespace XinjeMesProgram.Entities
{
    public class FactoryMesContext : DbContext
    {

        /// <summary>
        /// 数据库连接字符串.
        /// </summary>
        public static string SQLConnectStr { get; set; }

        //public FactoryMesContext()
        //{
        //}

        //public FactoryMesContext(DbContextOptions<FactoryMesContext> options)
        //    : base(options)
        //{
        //}
        /// <summary>
        /// 用户信息表.
        /// </summary>
        public DbSet<MesUserRole> MesUserRole { get; set; }

        /// <summary>
        /// 工程师表.
        /// </summary>
        public DbSet<MesUserRole12> MesUserRole12 { get; set; }

        /// <summary>
        /// 权限目录表.
        /// </summary>
        public DbSet<AuthMenu> AuthMenu { get; set; }

        /// <summary>
        /// 权限树目录映射.
        /// </summary>
        public DbSet<PermissionWithMenu> PermissionWithMenu { get; set; }

        /// <summary>
        /// 用户-角色多对多映射.
        /// </summary>
        public DbSet<AuthUserRoleMapping> AuthUserRoleMapping { get; set; }

        /// <summary>
        /// 角色-权限多对多映射.
        /// </summary>
        public DbSet<RolePermissionMapping> AuthRolePermissionMapping { get; set; }

        /// <summary>
        /// 角色数据集.
        /// </summary>
        public DbSet<AuthRole> AuthRole { get; set; }

        /// <summary>
        /// .
        /// </summary>
        public DbSet<PermissionWithAssignProperty> PermissionWithAssignProperty { get; set; }//DbQuery<PermissionWithAssignProperty>

        /// <summary>
        /// 用户信息表.
        /// </summary>
        public DbSet<UserInfoMangeModel> UserInfoManges { get; set; }
        
        /// <summary>
        /// 客户电话信息表.
        /// </summary>
        public DbSet<Customs> Customs { get; set; }

        /// <summary>
        /// 维修分拣表.
        /// </summary>
        public DbSet<MainsortRecordModel> MainsortRecord { get; set; }

        /// <summary>
        /// 分拣获取出库信息表.
        /// </summary>
        public DbSet<MainSortBookModel> MainSortBooks { get; set; }


        public DbSet<Deletedata> Deletedata { get; set; }


        /// <summary>
        /// 核对导出表.
        /// </summary>
        public DbSet<Verifyexport> Verifyexport { get; set; }

        /// <summary>
        /// 分拣产品型号表.
        /// </summary>
        public DbSet<GetProductType> GetProductTypes { get; set; }
        /// <summary>
        /// 维修记录表.
        /// </summary>
        public DbSet<RepairLog> RepairLog { get; set; }

        /// <summary>
        /// 维修
        /// </summary>
        public DbSet<RepairProductModel> RepairProduct { get; set; }

        /// <summary>
        /// 维修记录：问题分类：三个字段的信息（问题归类、故障类型、故障细分）
        /// </summary>
        public DbSet<ProblemGradeEntity> ProblemGrade { get; set; }

        /// <summary>
        /// 维修报告
        /// </summary>
        public DbSet<Report> Report { get; set; }

        /// <summary>
        /// 维修费用记录.
        /// </summary>
        public DbSet<MaintenanceCostModel> MaintenanceCost { get; set; }

        /// <summary>
        /// 发货表
        /// </summary>
        public DbSet<DeliverEntity> Deliver { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public DbSet<MaintenanceQueryModel> MaintenanceQueries { get; set; }

        /// <summary>
        /// 发货单号表.
        /// </summary>
        public DbSet<BookingListInfoModel> BookingListInfo { get; set; }

        /// <summary>
        /// 物料追踪表头.
        /// </summary>
        public DbSet<MaterialEntity> MaterialTracking { get; set; }

        /// <summary>
        /// 物料追踪表(数据).
        /// </summary>
        public DbSet<MaterialDataEntity> MaterialTracking2 { get; set; }

        /// <summary>
        /// 物料追踪表(子表数据).
        /// </summary>
        public DbSet<MaterialData2Entity> MaterialTracking3 { get; set; }

        public DbSet<BookingInfoIdsModel> BookingInfoIds { get; set; }

        /// <summary>
        /// 菜单数据集.
        /// </summary>
        /// <summary>
        /// .
        /// </summary>
        /// <param name="optionsBuilder">.</param>
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            optionsBuilder.UseSqlServer(SQLConnectStr);
        }

        /// <summary>
        /// .
        /// </summary>
        /// <param name="modelBuilder"></param>
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<MesUserRole>(entity =>
            {
                entity.HasKey(e => e.ID);

            });
            modelBuilder.Entity<PermissionWithMenu>(entity =>
            {
                entity.HasNoKey();
            });
            modelBuilder.Entity<PermissionWithAssignProperty>(entity =>
            {
                entity.HasNoKey();
            });
            modelBuilder.Entity<PermissionWithMenu>(entity =>
            {
                entity.HasNoKey();
            });
            modelBuilder.Entity<AuthUserRoleMapping>(entity =>
            {
                entity.HasKey(x => new
                {
                    x.UserGuid
                });
            });
            modelBuilder.Entity<RolePermissionMapping>(entity =>
            {
                entity.HasKey(x => new
                {
                    x.RoleCode,
                    x.PermissionCode,
                });
            });
            modelBuilder.Entity<UserInfoMangeModel>(entity =>
            {
                entity.HasNoKey();
            });
            modelBuilder.Entity<MainSortBookModel>(entity =>
            {
                entity.HasNoKey();
            });
            modelBuilder.Entity<MaintenanceQueryModel>(entity =>
            {
                entity.HasNoKey();
            });
            modelBuilder.Entity<BookingListInfoModel>(entity =>
            {
                entity.HasNoKey();
            });
            modelBuilder.Entity<BookingInfoIdsModel>(entity =>
            {
                entity.HasNoKey();
            });
            //this.OnModelCreatingPartial(modelBuilder);
        }
        //partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
    }

}
